package views.JPanel;

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import models.Constant;

public class MenuPanel extends javax.swing.JPanel
{

    private JFrame window;
    private int flag = 5;
    private ChucNangCB cncb;
    private ThongKe thongke;
    private Tim_kiem timkiem;
    private TTNhom ttnhom;
    private CaiDat caidat;
    public MenuPanel(JFrame window)
    {
        initComponents();
        this.window = window;
        cncb=new ChucNangCB(window);
        thongke=new ThongKe(window);
        timkiem=new Tim_kiem(window);
        caidat = new CaiDat(window);
        ttnhom=new TTNhom(window);
        ResetLayout();
        flag = 5;
        ttnhom.Show();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        btn_QuanLy = new javax.swing.JButton();
        btn_CheckOut = new javax.swing.JButton();
        btn_TimKiem = new javax.swing.JButton();
        btn_ThongKe = new javax.swing.JButton();
        btn_setting = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        btn_ThongTin = new javax.swing.JButton();

        jMenu1.setText("jMenu1");

        jMenu2.setText("jMenu2");


        setBackground(new java.awt.Color(51, 102, 255));

        btn_QuanLy.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/employee.png"))); // NOI18N
        btn_QuanLy.setText("Quản Lý Cán Bộ");
        btn_QuanLy.setBorderPainted(false);
        btn_QuanLy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_QuanLyActionPerformed(evt);
            }
        });

        btn_CheckOut.setBackground(new java.awt.Color(204, 204, 255));
        btn_CheckOut.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/logout.png"))); // NOI18N
        btn_CheckOut.setText("Thoát");
        btn_CheckOut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_CheckOutActionPerformed(evt);
            }
        });

        btn_TimKiem.setBackground(new java.awt.Color(204, 204, 255));
        btn_TimKiem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/btn_search.png"))); // NOI18N
        btn_TimKiem.setText("Tìm Kiếm");
        btn_TimKiem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_TimKiemActionPerformed(evt);
            }
        });

        btn_ThongKe.setBackground(new java.awt.Color(204, 204, 255));
        btn_ThongKe.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/my-profile.png"))); // NOI18N
        btn_ThongKe.setText("Thống kê");
        btn_ThongKe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_ThongKeActionPerformed(evt);
            }
        });

        btn_setting.setBackground(new java.awt.Color(204, 204, 255));
        btn_setting.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/config.png"))); // NOI18N
        btn_setting.setText("Cài đặt");
        btn_setting.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_settingActionPerformed(evt);
            }
        });

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        btn_ThongTin.setBackground(new java.awt.Color(204, 204, 255));
        btn_ThongTin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/contact-new.png"))); // NOI18N
        btn_ThongTin.setText("Thông Tin");
        btn_ThongTin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_ThongTinActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(18, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(btn_ThongKe, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_QuanLy, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_TimKiem, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_setting, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_ThongTin, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_CheckOut, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(btn_QuanLy, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                .addComponent(btn_TimKiem, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(btn_ThongKe, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(btn_setting, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(btn_ThongTin, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btn_CheckOut, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(37, 37, 37))
            .addComponent(jSeparator1)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btn_QuanLyActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btn_QuanLyActionPerformed
    {//GEN-HEADEREND:event_btn_QuanLyActionPerformed
        ResetLayout();
        flag = 1;
        cncb.Show();
    }//GEN-LAST:event_btn_QuanLyActionPerformed

    private void btn_TimKiemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btn_TimKiemActionPerformed
    {//GEN-HEADEREND:event_btn_TimKiemActionPerformed
        ResetLayout();
        flag = 2;
        timkiem.Show();
    }//GEN-LAST:event_btn_TimKiemActionPerformed

    private void btn_ThongKeActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btn_ThongKeActionPerformed
    {//GEN-HEADEREND:event_btn_ThongKeActionPerformed
        ResetLayout();
        flag = 3;
        thongke.Show();
    }//GEN-LAST:event_btn_ThongKeActionPerformed

    private void btn_CheckOutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_CheckOutActionPerformed
        if (JOptionPane.showConfirmDialog(this, "Bạn muốn đóng ứng dụng này ?", "Xác nhận đóng", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
            System.exit(1);
        }
    }//GEN-LAST:event_btn_CheckOutActionPerformed

    private void btn_settingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_settingActionPerformed
        ResetLayout();
        flag = 4;
        caidat.Show();
    }//GEN-LAST:event_btn_settingActionPerformed

    private void btn_ThongTinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ThongTinActionPerformed
        ResetLayout();
        flag = 5;
        ttnhom.Show();
    }//GEN-LAST:event_btn_ThongTinActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_CheckOut;
    private javax.swing.JButton btn_QuanLy;
    private javax.swing.JButton btn_ThongKe;
    private javax.swing.JButton btn_ThongTin;
    private javax.swing.JButton btn_TimKiem;
    private javax.swing.JButton btn_setting;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables

    public void Show()
    {
        this.setBounds(0, 0, 160, 600);
        this.setVisible(true);
        window.add(this);
    }

    public void Hide()
    {
        this.setVisible(false);
    }

    private void ResetLayout()
    {
        Hide();
        Show();
        switch (flag)
        {
            case 1:
                cncb.setVisible(false);
                break;
            case 2:
                timkiem.setVisible(false);
                break;
            case 3:
                thongke.setVisible(false);
                break;
            case 4:
                caidat.setVisible(false);
                break;
            case 5:
                ttnhom.setVisible(false);
                break;
            default:
                break;
        }
    }
}
